



/* Compute number of distinct trustees */



clear all

use "G:\Data\Workdata\707677\Common\01Data\02STATA\panel_iv", clear 

cd  G:\Data\Workdata\707677\Common\03Output\02Regresssions




keep if time==1

keep pnr court time lawyerid granted obs_lawyer iv_court obs_court aar


tab obs_lawyer

egen lawyer_id_unique =group(lawyerid court) // Unique lawyer id within courts. some lawyers work in multiple courts

bys lawyer_id_unique: egen n_lawyer=count(lawyer_id_unique)
egen mean_lawyer_leniency= mean(granted), by(lawyer_id_unique)

gen iv_judge2_all = (mean_lawyer_leniency*n_lawyer - granted)/(n_lawyer-1)

gen iv_lawyer2=iv_judge2_all-(iv_court*obs_court-granted)/(obs_court-1)




/* Number of distinct lawyer_court combinations with no restrictions on cases per trustee */

sort lawyer_id_unique

by lawyer_id_unique: gen id=_n

tab id if id==1





/* Number of distinct lawyers with no restrictions on cases per trustee */



sort lawyerid

by lawyerid: gen lid=_n

tab lid if lid==1






* Data restrictions more than 20 obs pr lawyer and multiple lawyers in a given court*year



keep if n_lawyer>=20

egen n_judge=nvals(lawyer_id_unique), by(court aar)



tab n_judge

keep if n_judge>1







/* Number of distinct lawyer_court combinations with restrictions on cases per trustee */

sort lawyer_id_unique

by lawyer_id_unique: gen id_restricted=_n

tab id_restricted if id_restricted==1





/* Number of distinct lawyers with restrictions on cases per trustee */



sort lawyerid

by lawyerid: gen lid_restricted=_n

tab lid_restricted if lid_restricted==1





/* How many distinct lawyers work in more than one court */

sort lawyerid court

by lawyerid court: gen newid=_n



keep if newid==1


sort lawyerid

by lawyerid: gen lcount=_n

tab lcount




